package com.darrenchan.course08

/**
  * 这个要写在最前面
  * 所谓转换的时机，就是该对象执行的方法不是它本身自带的方法
  */
object MyPre {
  implicit def dogToPerson(dog: Dog) = {
    new Person()
  }

  implicit def personToDog(person: Person) = {
    new Dog()
  }

}

object PersonAndDog {
  def main(args: Array[String]): Unit = {
    val stu1 = new Person()
    val stu2 = new Person()
    val dog = new Dog()

    //    stu1.makeFriends(stu2)
    import MyPre._
    stu1.makeFriends(dog)
  }
}

class Person {
  def makeFriends(p: Person) = {
    println("人和人交朋友")
  }
}

class Dog {
  def makeFriends(dog: Dog) = {
    println("狗和人交朋友")
  }
}

